/**
 * 
 */
$(document).ready(function() {
	
	next();

});

var next = function(){
	$.ajax({
		url:'sys/Client/list',
		data:{'isNonPage':1,comp:1,'beanProxy[enable]':0},
		type:'post',
		dataType:'json',
		async:false,
		success:function(result){
			if(typeof(result)!='undefined' && result.state == 200){
				var tbody = $('#tbody');
				tbody.empty();
				$('ul.placeul li.last2').remove();
				$('ul.placeul li.last3').remove();
				$('ul.placeul li.last4').remove();
				$('ul.placeul li.last5').remove();
				var trs = result.rows;
				if(_is_not_empty(trs)){
					var length = trs.length,str='';
					while(--length>=0){
						var one = trs[length];
						str = str + '<tr><td><a href="javascript:void(0);" onclick="next1('+one.id+')"><img src="static_resources/images/f01.png" />'+one.clientName+'</td>';
						str = str + '<td>'+new Date(one.addTime).format('yyyy/MM/dd HH:mm')+'</td>';
						str = str + '<td>文件夹</td>';
						str = str + '<td>'+'</td>';
						str = str + '<td><a href="javascript:void(0);" onclick="packageNext('+one.id+')" class="tablelink">'+'打包下载</a></td>';
						str = str + '</tr>';
					}
					tbody.append($(str));
				}
	           
			}
		},
		complete:function(){
		}
	});
};

var next1 = function (id){
	$.ajax({
		url:'sys/Loan/list',
		data:{'isNonPage':1,comp:1,'beanProxy[enable]':0,'beanProxy[clientId]':id},
		type:'post',
		dataType:'json',
		async:false,
		success:function(result){
			if(typeof(result)!='undefined' && result.state == 200){
				var tbody = $('#tbody');
				tbody.empty();
				$('ul.placeul li.last2').remove();
				$('ul.placeul li.last3').remove();
				$('ul.placeul li.last4').remove();
				$('ul.placeul li.last5').remove();
				var trs = result.rows;
				if(_is_not_empty(trs)){
					var length = trs.length,str='';
					while(--length>=0){
						var one = trs[length];
						str = str + '<tr><td><a href="javascript:void(0); onclick=next2('+one.id+','+id+')"><img src="static_resources/images/f01.png" />'+one.loanCode+'</td>';
						str = str + '<td>'+new Date(one.addTime).format('yyyy/MM/dd HH:mm')+'</td>';
						str = str + '<td>文件夹</td>';
						str = str + '<td></td>';
						str = str + '<td><a href="javascript:void(0); onclick=packageNext1('+one.id+','+id+')" class="tablelink">'+'打包下载</a></td>';
						str = str + '</tr>';
					}
					tbody.append($(str));
				}
	           $('ul.placeul li.last1').after('<li class="last2"><a href="javascript:void(0);onclick=next()">返回客户列表</a></li>');
			}
		},
		complete:function(){
		}
	});
}

var next2 = function (id,pid){
	$.ajax({
		url:'sys/SysAccessoryExt/selectAccessoryType',
		data:{'isNonPage':1,'queryProxy[clientId]':pid,'queryProxy[loanId]':id},
		type:'post',
		dataType:'json',
		async:false,
		success:function(result){
			if(typeof(result)!='undefined'){
				var tbody = $('#tbody');
				tbody.empty();
				$('ul.placeul li.last3').remove();
				$('ul.placeul li.last4').remove();
				$('ul.placeul li.last5').remove();
				var trs = result;
				if(_is_not_empty(trs)){
					var length = trs.length,str='';
					while(--length>=0){
						var one = trs[length];
						
						str = str + '<tr><td><a href="javascript:void(0); onclick=next3(\''+one.ownerType+'\','+id+','+pid+')"><img src="static_resources/images/f01.png" />'+top.SYS_BASE_DATA['Accessory_Loan_ownerType_Code'][one.ownerType]+'</td>';
						str = str + '<td>'+(_is_empty(one.lastUpdatetime)?new Date(one.addTime).format('yyyy/MM/dd HH:mm'):new Date(one.lastUpdatetime).format('yyyy/MM/dd HH:mm'))+'</td>';
						str = str + '<td>文件夹</td>';
						str = str + '<td></td>';
						str = str + '<td><a href="javascript:void(0); onclick=packageNext2(\''+one.ownerType+'\','+id+','+pid+')" class="tablelink">'+'打包下载</a></td>';
						str = str + '</tr>';
					}
					tbody.append($(str));
				}
	           $('ul.placeul li.last2').after('<li class="last3"><a href="javascript:void(0);onclick=next1('+pid+')">返回贷款列表</a></li>');
			}
		},
		complete:function(){
		}
	});
}
	
var next3 = function (type,pid1,pid2){
		$.ajax({
			url:'sys/SysAccessoryExt/selectAccessoryClass',
			data:{'isNonPage':1,'queryProxy[clientId]':pid2,'queryProxy[loanId]':pid1,'queryProxy[ownerType]':type},
			type:'post',
			dataType:'json',
			async:false,
			success:function(result){
				if(typeof(result)!='undefined'){
					var tbody = $('#tbody');
					tbody.empty();
					$('ul.placeul li.last5').remove();
					$('ul.placeul li.last4').remove();
					var trs = result;
					if(_is_not_empty(trs)){
						var length = trs.length,str='';
						while(--length>=0){
							var one = trs[length];
							var accessoryClass = top.SYS_BASE_DATA['Accessory_Class_Apply_Code'][one.accessoryClass];
							if(_is_not_empty(one.accessoryClass) && one.accessoryClass =='HT'){
								accessoryClass = top.SYS_BASE_DATA['Accessory_Class_Contract_Code'][one.accessoryClass];
							}
							str = str + '<tr><td><a href="javascript:void(0); onclick=next4(\''+one.accessoryClass+'\','+'\''+type+'\','+pid1+','+pid2+')"><img src="static_resources/images/f01.png" />'+accessoryClass+'</a></td>';
							str = str + '<td>'+(_is_empty(one.lastUpdatetime)?new Date(one.addTime).format('yyyy/MM/dd HH:mm'):new Date(one.lastUpdatetime).format('yyyy/MM/dd HH:mm'))+'</td>';
							str = str + '<td>文件夹</td>';
							str = str + '<td></td>';
							str = str + '<td><a href="javascript:void(0); onclick=packageNext3(\''+one.accessoryClass+'\','+'\''+type+'\','+pid1+','+pid2+')" class="tablelink">'+'打包下载</a></td>';
							str = str + '</tr>';
						}
						tbody.append($(str));
					}
		           $('ul.placeul li.last3').after('<li class="last4"><a href="javascript:void(0);onclick=next2('+pid1+','+pid2+')">返回附件类别</a></li>');
				}
			},
			complete:function(){
			}
		});
}


var next4 = function (accessoryClass,type,pid1,pid2){
	$.ajax({
		url:'sys/SysAccessory/list',
		data:{'isNonPage':1,'beanProxy[enable]':0,'beanProxy[clientId]':pid2,'beanProxy[loanId]':pid1,'beanProxy[ownerType]':type,'beanProxy[accessoryClass]':accessoryClass},
		type:'post',
		dataType:'json',
		async:false,
		success:function(result){
			if(typeof(result)!='undefined'){
				var tbody = $('#tbody');
				tbody.empty();
				//$('ul.placeul li.last5').remove();
				var trs = result.datagrid.aaData;
				if(_is_not_empty(trs)){
					var length = trs.length,str='';
					while(--length>=0){
						var one = trs[length];
						str = str + '<tr><td><img src="static_resources/images/'+(top.fileIcon[one.accessoryType]||'f02.png')+'" />'+one.accessoryTheme+'</td>';
						str = str + '<td>'+(_is_empty(one.lastUpdatetime)?new Date(one.addTime).format('yyyy/MM/dd HH:mm'):new Date(one.lastUpdatetime).format('yyyy/MM/dd HH:mm'))+'</td>';
						str = str + '<td>文件</td>';
						str = str + '<td>'+one.accessoryFileSize+' '+one.accessoryFileUnit+'</td>';
						str = str + '<td><a href="javascript:void(0); onclick=packageIngByPK('+one.id+')" class="tablelink">'+'打包下载</a>&nbsp;'+'|&nbsp;<a href="javascript:void(0); onclick=edit('+one.id+',\''+one.accessoryClass+'\','+'\''+type+'\','+pid1+','+pid2+')" class="tablelink">'+'编辑</a>'+'</td>';
						str = str + '</tr>';
					}
					tbody.append($(str));
				}
	           $('ul.placeul li.last4').after('<li class="last5"><a href="javascript:void(0);onclick=next3(\''+type+'\','+pid1+','+pid2+')">返回附件类型</a></li>');
			}
		},
		complete:function(){
		}
	});
}


var edit = function(id,accessoryClass,type,loanId,clientId){
	$.dialog.confirm('以前的附件将被覆盖，确定修改附件吗？', function(){
		$.dialog({
			id:'_accessory_upload_dailog',
			title:'上传/编辑附件',
			lock:true,
			width:700,
			height:400,
			content:'url:'+parent.basePath+'jsp/loan/accessory_upload.jsp?loanId='+loanId+'&clientId='+clientId+'&id='+id,
			close: function(){
				next4(accessoryClass,type,loanId,clientId);
		    }
		});
	});
}

//更加ID打包下载loanId,clientId,ownerType,accessoryClass
var packageIngByPK = function(id){
	window.location.href = 'sys/SysAccessoryExt/packageAccessory?id='+id;
}

var packageNext3 = function(accessoryClass,ownerType,loanId,clientId){
	window.location.href = 'sys/SysAccessoryExt/packageAccessory?accessoryClass='+accessoryClass+'&ownerType='+ownerType+'&loanId='+loanId+'&clientId='+clientId;
}

var packageNext2 = function(ownerType,loanId,clientId){
	window.location.href = 'sys/SysAccessoryExt/packageAccessory?ownerType='+ownerType+'&loanId='+loanId+'&clientId='+clientId;
}

var packageNext1 = function(loanId,clientId){
	window.location.href = 'sys/SysAccessoryExt/packageAccessory?loanId='+loanId+'&clientId='+clientId;
}
var packageNext = function(clientId){
	window.location.href = 'sys/SysAccessoryExt/packageAccessory?clientId='+clientId;
}